package logic

import (
	"context"
	"month2/C/rpc_C/order"

	"month2/C/api_C/internal/svc"
	"month2/C/api_C/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type CreateOrderLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewCreateOrderLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateOrderLogic {
	return &CreateOrderLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *CreateOrderLogic) CreateOrder(req *types.CreateOrderRequest) (resp *types.Response, err error) {
	l.ctx.Value("UserId")
	createOrder, err := l.svcCtx.CRpc.CreateOrder(l.ctx, &order.CreateOrderRequest{
		GoodsId: int64(req.GoodsId),
	})
	if err != nil {
		return &types.Response{
			Msg:  err.Error(),
			Data: nil,
			Code: 500,
		}, nil
	}
	return &types.Response{
		Msg:  "下单成功",
		Data: createOrder,
		Code: 200,
	}, nil
}
